const {
	override,
	overrideDevServer,
	watchAll,
	addWebpackAlias,
	addWebpackPlugin,
	fixBabelImports
} = require("customize-cra");	
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); // 代码压缩
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); // 大文件定位
const ProgressBarPlugin = require('progress-bar-webpack-plugin'); // 打包进度
const CompressionPlugin = require('compression-webpack-plugin'); // gzip压缩
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); // css压缩
const path = require('path')

module.exports = override(
	addWebpackAlias({
		["@"]: path.resolve(__dirname, "src")
	}),
	fixBabelImports('import', {
		libraryName: 'antd',
		libraryDirectory: 'es',
		style: true,
	}),
	// 注意是production环境启动该plugin
	process.env.NODE_ENV === 'production' &&
	addWebpackPlugin(
		new UglifyJsPlugin({
			// 开启打包缓存
			cache: true,
			// 开启多线程打包
			parallel: true,
			uglifyOptions: {
				// 删除警告
				warnings: false,
				// 压缩
				compress: {
					// 移除console
					drop_console: true,
					// 移除debugger
					drop_debugger: true,
				},
			},
		})
	),
	process.env.NODE_ENV === 'production' && addWebpackPlugin(new MiniCssExtractPlugin()),
	// 判断环境变量ANALYZER参数的值
	process.env.NODE_ENV === 'production' && addWebpackPlugin(new BundleAnalyzerPlugin()),
	// 打包进度条
	addWebpackPlugin(new ProgressBarPlugin()),
);

